#include "crcchecktool.h"

namespace Common {

quint16 CrcCheckTool::Crc16check(char *data, int length)
{
    ushort t_reg;
    ushort t_temp;
    ushort t_crcCode;
    t_reg = 0xFFFF;
    t_crcCode = 0xA001;
    for(int i = 0; i < length; i++)
    {
        t_reg ^= *(data+i);
        for(int j  = 0; j< 8; j++)
        {
            t_temp = t_reg & 0x0001;
            t_reg = t_reg >> 1;
            if( 0x0001 == t_temp)
            {
                t_reg ^= t_crcCode;
            }
        }
    }
    return (t_reg << 8 | t_reg >> 8);
}

}//namespace Common
